﻿//双击事件
function CustomDbClick() {
    //parent.closeWin(); //去掉双击功能
    fnViewDetail();
}

//新增分类
var fnAddCalss = function () {
    //debugger;
    document.getElementById("EditUIWindow").src = "../EHR/hrExaminationItemType.aspx?r=" + Math.random() +"&flag=Add";
    SetDWH(300, 120, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
    parent.NeedRefreshPage = this;
}

//删除分类
var fnDelCalss = function () {
    //debugger;
    //alert("_key:" + _key + " _Caption:" + _Caption)
    var CategoryID = _key;
    if (CategoryID == null || CategoryID == "") {
        alert("请选择要删除的分类！");
        return;
    }
    var CategoryName = _Caption;
    const_EditEntity = "DatSkillCategory";
    if (CategoryName == "项目分类") {
        alert("根目录不能删除！");
        return;
    }
    if (confirm("删除后将无法恢复,确定要删除吗?")) {
        YAHOO.util.Connect.asyncRequest('POST', "../EHR/hrExaminationAjax.aspx?flag=delExaminationItemType" + "&id=" + CategoryID, {
            success: function (res) {
                try {
                    var str = res.responseText;
                    if (str == "1") {
                        alert("删除成功!")
                        deleteNode();
                    }
                    else {
                        alert(str)
                        return;
                    }
                }
                catch (e) {
                    alert("删除失败：" + e.Message);
                    return;
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
                return;
            }
        }, null);
    }
}

//新增
var fnCustomAdd = function () {
    var CategoryID = _key;
    if (CategoryID == null || CategoryID == "") {
        alert("请选择分类！");
        return;
    }
    var CategoryName = _Caption;
    if (CategoryName == "项目分类") {
        alert("根目录不能创建项目！");
        return;
    }

    const_EditEntity = "ExaminationItem";
    var pagetitle = "新增考核项目";
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&flag=add" + "&CategoryID=" + CategoryID + "&CategoryName=" + CategoryName));
    //parent.NeedRefreshPage = this;
}

//修改
var fnCustomEdit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    const_EditEntity = "ExaminationItem";
    //debugger
    var pagetitle = "修改考核项目_" + record._oData["itemname"];
    var CategoryName = record._oData["cateoryname"];
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&flag=edit" + "&id=" + record.getData(const_entityID) + "&CategoryName=" + CategoryName));
    //parent.NeedRefreshPage = this;
}

//查看
var fnViewDetail = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    const_EditEntity = "ExaminationItem";
    //debugger;
    var pagetitle = "查看考核项目_" + record._oData["itemname"];
    var CategoryName = record._oData["cateoryname"];
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&flag=view" + "&id=" + record.getData(const_entityID) + "&CategoryName=" + CategoryName));
    parent.NeedRefreshPage = this;
}


//删除
var fnCustomDelete = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    //debugger;
    var list = this.mDataTable.getRecordSet()._records;
    var elist = [];
    dl = [];
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData["iSun_Selected"] == true) {
            elist.push(list[i]._oData[const_entityID]);
            dl.push(list[i]._sId); //获取行ID；
        }
    }

    var id = record.getData(const_entityID);
    //第一步先删除相关的引用表信息、子表、主表
    YAHOO.util.Connect.asyncRequest('POST', "../EHR/hrExaminationAjax.aspx?flag=delExaminationItem" + "&json=" + elist.join(","), {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "1") {
                    //第二步
                    var list = mDataTable.getRecordSet()._records;
                    dl = [];
                    for (var i = 0; i < list.length; i++) {
                        if (list[i]._oData["iSun_Selected"] == true) {
                            dl.push(list[i]._sId); //获取行ID；
                        }
                        SaveUrl = "../Extend/AjaxData/DataSave.aspx?r=" + Math.random() + "&action=delete&entity=" + const_EditEntity + "&id=" + id;
                        YAHOO.example.container.dialog3.show();
                    }
                }
                else {
                    alert(str);
                    return;
                }
            }
            catch (e) {
                alert("删除失败：" + e.Message);
                return;
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
            return;
        }
    }, null);
}




